package com.guaju.yueshangLife.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.bean.MeOrder;
import com.guaju.yueshangLife.bean.OrderDetailBean;

import java.util.List;

public class OrderDetailInnerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    Context context;
    List<OrderDetailBean.DataBean.ItemsBean> list;
    private int status = 1;


    Activity activity;
    private final LayoutInflater layoutInflater;
    private View view;

    public OrderDetailInnerAdapter(Context context, List<OrderDetailBean.DataBean.ItemsBean> list) {
        this.context = context;
        this.list = list;
        activity = (Activity) context;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int type) {
        View view = layoutInflater.inflate(R.layout.item_order_inner, parent, false);
        InnerHolder innerHolder = new InnerHolder(view);
        return innerHolder;

    }

    //绑定
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        InnerHolder innerHolder = (InnerHolder) holder;
        innerHolder.setContent(list.get(position));
    }

    //有多少个item？
    @Override
    public int getItemCount() {
        return list.size();
    }


    public interface OnItemClickListener {
        void onItemClick(View v, int position);

        void onItemLongClick(View v);
    }

    public OrderDetailInnerAdapter.OnItemClickListener mOnItemClickListener;//第二步：声明自定义的接口

    //第三步：定义方法并暴露给外面的调用者
    public void setOnItemClickListener(OrderDetailInnerAdapter.OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }


    class InnerHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        SimpleDraweeView sdv_inner;
        TextView tv_inner_title, tv_inner_attr, tv_inner_num, tv_inner_price;

        public InnerHolder(View itemView) {
            super(itemView);
            sdv_inner = itemView.findViewById(R.id.sdv_inner);
            tv_inner_attr = itemView.findViewById(R.id.tv_inner_attr);
            tv_inner_title = itemView.findViewById(R.id.tv_inner_title);
            tv_inner_num = itemView.findViewById(R.id.tv_inner_num);
            tv_inner_price = itemView.findViewById(R.id.tv_inner_price);
            itemView.setOnClickListener(this);

        }

        public void setContent(OrderDetailBean.DataBean.ItemsBean bean) {
            sdv_inner.setImageURI(bean.getDetail().getCover().getHost() + bean.getDetail().getCover().getPath());
            List<String> attribute = bean.getDetail().getAttribute();
            String info = "";
            for (String str : attribute) {
                info += str + ";";
            }
            tv_inner_attr.setText(info.substring(0, info.length() - 1));
            tv_inner_num.setText("x "+bean.getAmount());
            tv_inner_title.setText(bean.getDetail().getName());
            tv_inner_price.setText("¥ "+bean.getPrice());



        }

        @Override
        public void onClick(View v) {
        }
    }


}
